<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>田忌赛马</title>
</head>

<body>
  <script>
    function arr(nums1, nums2) {
      let a = nums1.map((v, i) => i)
      let b = nums2.map((v, i) => i)
      a.sort((i, j) => nums1[i] - nums1[j])
      b.sort((i, j) => nums2[i] - nums2[j])
      let res = []
      for (let i = 0, l = 0, r = b.length - 1; i < a.length; i++) {
        if (nums1[a[i]] <= nums2[b[l]]) {
          res[b[r]] = nums1[a[i]]
          r--
        }
        else {
          res[b[l]] = nums1[a[i]]
          l++
        }
      }
      return res
    };
    console.log(arr([2, 7, 11, 15], [1, 10, 4, 11]));
  </script>
</body>

</html>